let mysql = require('mysql');


module.exports = (sql,params=[]) => {
    //1.创建链接对象
    let connection = mysql.createConnection({
        host:'localhost',
        user:'root',
        password:'root',
        database:'zk2_1810'
    })

    //2.链接
    connection.connect();

    return new Promise((resolve,reject) => {
        //3.交互
        connection.query(sql,params,(error,result) => {
            if(error){
                reject(error)
            }else{
                resolve(result);
            }
            //4.关闭连接
            connection.end();
        })
    })
}